<?php
  include_once "./common/checkLogin.php";
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Comments &laquo; Admin</title>
  <link rel="stylesheet" href=".././static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href=".././static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href=".././static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href=".././static/assets/css/admin.css">
  <script src=".././static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>
  <div class="main">
  <?php include_once 'common/nav.php'?>
    <div class="container-fluid">
      <div class="page-title">
        <h1>所有评论</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <div class="page-action">
        <!-- show when multiple checked -->
        <div class="btn-batch" style="display: none">
          <button class="btn btn-info btn-sm">批量批准</button>
          <button class="btn btn-warning btn-sm">批量拒绝</button>
          <button class="btn btn-danger btn-sm">批量删除</button>
        </div>
        <ul class="pagination pagination-sm pull-right">
         
        </ul>
      </div>
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th class="text-center" width="40"><input type="checkbox"></th>
            <th>作者</th>
            <th>评论</th>
            <th>评论在</th>
            <th>提交于</th>
            <th>状态</th>
            <th class="text-center" width="100">操作</th>
          </tr>
        </thead>
        <tbody>
         
          
        </tbody>
      </table>
    </div>
  </div>

  <?php include_once 'common/aside.php'?>

  <script src=".././static/assets/vendors/jquery/jquery.js"></script>
  <script src=".././static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script src=".././static/assets/vendors/art-template/template-web.js"></script>
  <script src=".././static/assets/vendors/twbs-pagination/jquery.twbsPagination.js"></script>
  <script type="text/template" id="tel">
    {{each data}}
         <tr>
            <td class="text-center"><input type="checkbox"></td>
            <td>{{$value.author}}</td>
            <td>{{$value.content}}</td>
            <td>{{$value.title}}</td>
            <td>{{$value.created}}</td>
            <td>
                {{if($value.status=="held")}}
                   待审核          
                {{else if($value.status=="rejected")}}
                   准许              
                {{else if($value.status=="trashed")}}
                   回收站
                {{else if($value.status=="approved")}}
                    批准            
                {{/if}}
              </td>
            <td class="text-center">
              <a href="post-add.php" class="btn btn-info btn-xs">批准</a>
              <a href="javascript:;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
    {{/each}}
  </script> 
  <script>NProgress.done()</script>
</body>
<script>
     var currentpage=1;
     var pageSize=10;
    

     function getComments(currentpage,pageSize){
         $.ajax({
         type:'post',
         url:'./api/getComment.php',
         data:{"currentpage":currentpage,"pageSize":pageSize},
         dataType:'json',
         success:function(res){
         var html=template('tel',res);
         $('tbody').html(html);

         var Maxpage=Math.ceil(res.count/pageSize);
        

         $('.pagination').twbsPagination({
            totalPages: Maxpage,
            visiblePages: 5,
            first:'首页',
            prev:'上一页',
            next:'下一页',
            last:'尾页',
         onPageClick: function (event, page) {
          getComments(page,pageSize);
             }
          });
        }
      })
     }
 getComments(currentpage,pageSize);

</script>
</html>
